global path="C:\Users\mcsam"
*global path="C:\Users\srb834"
*global path="D:"
global path2="Decomposing Firm Betas"

cd "$path\Dropbox\Decomposing Firm Betas\Submissions\JPE Macro\Replication Folder"
use Figure_5_data,clear

gen name=""
gen slope=.
gen avg_overlap=.

local z=1
levelsof category1 if sga!=. & churn!=. & sale!=.,local(cats)
foreach cat of local cats{
	reg sga churn sale if cat=="`cat'"
	if `z'==1{
		outreg2 using test, replace ctitle("`cat'")
	}
	else{
		outreg2 using test, append ctitle("`cat'")
	}
	replace name="`cat'" if _n==`z'
	replace slope=_b[churn] if _n==`z'
	sum overlap if category1=="`cat'"
	replace avg_overlap=`r(mean)' if _n==`z'
	local z=`z'+1
}

reg slope avg_overlap
local slope=round(_b[avg_overlap],0.01)
local se=round(_se[avg_overlap],0.01)
twoway (scatter slope avg_overlap,mlabel(name) xlabel(0(.005).04) ) (lfit slope avg_overlap), xtitle("Avg. Within-Category Overlap") ytitle("Slope between SG&A/Sales and Churn") graphregion(color(white)) legend(off) subtitle("All Categories") note("Slope: `slope'; SE: `se'")
graph save 1.gph,replace

reg slope avg_overlap if name!="Restaurants"
local slope=round(_b[avg_overlap],0.01)
local se=round(_se[avg_overlap],0.01)
twoway (scatter slope avg_overlap,mlabel(name) xlabel(0(.005).04) ) (lfit slope avg_overlap) if name!="Restaurants", xtitle("Avg. Within-Category Overlap") ytitle("Slope between SG&A/Sales and Churn") graphregion(color(white)) legend(off) subtitle("Excluding Restaurants") note("Slope: `slope'; SE: `se'")
graph save 2.gph,replace

graph combine 1.gph 2.gph,  graphregion(color(white))
